<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;
/**
 * Created by PhpStorm.
 * User: 空房间
 * Date: 2018/2/23
 * Time: 10:31
 */
class Registeredfee extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->db=new \app\admin\model\Registeredfee;
    }
    public function reg_list()
    {
        $info = $this->db->reg_list();
        $this->assign('info',$info);
        return view();
    }

    /**
     * 添加数据
     * @return \think\response\View|void
     */
    public function reg_add()
    {
        if(Request::instance()->isPost()){
            $data = input('post.');
            if(!empty($data)){
                $inser_info = array(
                    'uid'          =>  '23',//假数据
                    'subbranch_id'=> '2',//假数据
                    'create_time'=>time(),
                    'update_time'=>time()
                );
                $data = array_merge($data,$inser_info);
                $result = $this->db->reg_add($data);
                return  $result ? $this->success('成功') : $this->error('失败');
            }
        }
        return view();
    }
    /**
     * 修改数据
     */
    public function reg_edit()
    {
       if(Request::instance()->isPost()){
            $data = input('post.');
            if(!isset($data['id'])||!$data['id']){
                $this->error('参数不全操作失败');die;
            }
            $inser_info = array(
                'uid'          =>  '23',//假数据
                'subbranch_id'=> '2',//假数据
                'update_time'=>time()
            );
            $data = array_merge($data,$inser_info);
            $result = $this->db->update_info($data['id'],$data);
            return $result ? $this->success('成功') : $this->error('失败');
        }
        $id = input('get.id');
        $info = $this->db->getInfoById(array('reg_id'=>$id));
        $this->assign('info',$info);
        return view();
    }
    /**
     * 数据删除
     */
    public function reg_del()
    {
        $id=input('post.id',0,'intval');
        if(!$id){
            $result = array(
                'status' =>0,
                'message'=>'参数错误，无法删除'
            );
        }else{
            $re=$this->db->del_info($id);
            if(!$re){
                $result = array(
                    'status' =>0,
                    'message'=>'删除失败'
                );
            }else{
                $result = array(
                    'status' =>1,
                    'message'=>'删除成功'
                );
            }
        }


        echo json_encode($result);
    }
    /**
     * 批量删除
     */
    public function all_reg_del(){
        $ids = input('post.ids/a');
        if(empty($id)){
            $result = array(
                'status' =>0,
                'message'=>'无可删除对象'
            );
        }else{
            $re = $this->db->all_del_info($ids);
            if(!$re){
                $result = array(
                    'status' =>0,
                    'message'=>'删除失败'
                );
            }else{
                $result = array(
                    'status' =>1,
                    'message'=>'删除成功'
                );
            }
        }
        echo json_encode($result);
    }
}